package com.weimin.ghostdrop.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : huiMing
 * Date : 2025年09月08日 10:20
 * @version V1.0
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${file.upload-dir}")
    private String uploadDir;

    @Value("${file.base-url}")
    private String baseUrl;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置 /images/** 路径映射到本地文件系统的 uploadDir 目录
        // 注意: file: 后面的路径需要以 / 结尾
        String uploadPath = "file:" + uploadDir;
        if (!uploadPath.endsWith("/")) {
            uploadPath += "/";
        }
        registry.addResourceHandler(baseUrl + "**")
                .addResourceLocations(uploadPath);
    }
}
